## auto load
extends Node



var _interactive_areas: Array[InteractiveArea]
var _curr_area: InteractiveArea


func _process(_delta: float) -> void:
    if _interactive_areas.is_empty(): return

    var first := _interactive_areas.front() as InteractiveArea
    if first != _curr_area:
        _curr_area = first
        _curr_area.tip_node.show()


func _unhandled_key_input(event: InputEvent) -> void:
    if _curr_area == null: return
    if _curr_area.tip_node.visible and event.is_action_pressed("interact"):
        _curr_area.interacted.emit()
        _interactive_areas.pop_front()
        _curr_area.tip_node.hide()
        _curr_area = null


func add_interaction(area: InteractiveArea) -> void:
    _interactive_areas.append(area)


func remove_interaction(area: InteractiveArea) -> void:
    var index := _interactive_areas.find(area)
    if index == -1: return
    if _curr_area == area:
        _curr_area = null
    area.tip_node.hide()
    _interactive_areas.remove_at(index)
